<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>关健字列表</title>
		
		<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
		 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/themes/flexigrid/css/flexigrid.css" />
		<script type="text/javascript" src="<%=request.getContextPath() %>/script/jquery.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath() %>/script/grid/flexigrid.js"></script>
		<style type="text/css" media="all"> 
			@import "<%=request.getContextPath() %>/themes/flexigrid/css/thickbox.css"; 
		</style>
		<link rel="alternate stylesheet" type="text/css" href="<%=request.getContextPath() %>/themes/flexigrid/css/1024.css" title="1024 x 768" />
		<script src="<%=request.getContextPath() %>/script/grid/thickbox.js" type="text/javascript"></script>
		<style>
			.flexigrid div.fbutton .add {
				background: url(<%=request.getContextPath() %>/themes/flexigrid/images/add.png) no-repeat center left;
			}
			
			.flexigrid div.fbutton .delete {
				background: url(<%=request.getContextPath() %>/themes/flexigrid/images/close.png) no-repeat center left;
			}
			.flexigrid div.fbutton .edit {
				background: url(<%=request.getContextPath() %>/themes/flexigrid/images/plugin.gif) no-repeat center left;
			}
			.flexigrid div.fbutton .copy {
				background: url(<%=request.getContextPath() %>/themes/flexigrid/images/copy.gif) no-repeat center left;
			}
		</style>

	</head>

	<body>
	
	<div class="bborderx">
		<table id="flex1" style="display:none"></table>
	</div>
	<!--  隐藏一个按钮 ，用来调用thickbox  -->
	<div style="display:none;">
		<input type="button" id="cssrain" href="<%=request.getContextPath() %>/pages/admin/keyword/addKeyWord.jsp?height=200&amp;width=300" title="添加关键字" class="thickbox" value="关键字" />
		<input type="button" id="cssrainupdate" href="" title="修改关键字" class="thickbox" value="aaa" />
	</div>	

	<div style="display:none;">
		<input type="button" id="errorrain" href="<%=request.getContextPath() %>/common/delErro.html?height=200&amp;width=300" title="出错信息！" class="thickbox" value="" />
	</div>		
		<script type="text/javascript">
			$("#flex1").flexigrid
			(
			{
			url: '<%=request.getContextPath() %>/keyWord.do?method=standGridQuery',
			dataType: 'json',
			errormsg: '连接错误！',
			colModel : [
				{display: '主键', name : 'id', width : 60, sortable : true, align: 'left',hide: true},
				{display: '编号', name : 'numid', width : 60, sortable : true, align: 'center'},
				{display: '名称', name : 'keyword_name', width : 120, sortable : true, align: 'left'},
				{display: '点击次数', name : 'keyword_clickNum', width : 120, sortable : true, align: 'left'},
				{display: '填写人', name : 'sys_fille', width : 120, sortable : true, align: 'left'},
				{display: '填写时间', name : 'sys_time', width : 120, sortable : true, align: 'left'}
				],
			buttons : [
				{name: '增加', bclass: 'add', onpress : exOperation},
				{name: '修改', bclass: 'edit', onpress : exOperation},
				{name: '复制', bclass: 'copy', onpress : exOperation},
				{name: '删除', bclass: 'delete', onpress : exOperation},
				{separator: true}
				],
			searchitems : [
				{display: '名称', name : 'keyword_name', isdefault: true}
				],
			sortname: "keyword_clickNum",
			sortorder: "asc",
			usepager: true,
			title: '关键字',
			useRp: true,
			singleSelect: false,
			ifDblclick: false,
			rp: 10,
			showTableToggleBtn: true,
			width: $(window).width()-2,
			height: 600
			}
			);
			
			//操作数据
			function exOperation(com,grid){
				if (com=='删除'){
					if( $('.trSelected',grid).length>0){
						if(confirm('是否删除这 ' + $('.trSelected',grid).length + ' 条记录吗?')){
							  var  id ="";
							  //debugger;
						     for(var i=0;i<$('.trSelected',grid).length;i++){
						        id += "id="+$('.trSelected',grid).find("td:first").eq(i).text()+"&";
						     }
						      $.ajax({ 
								url: "<%=request.getContextPath()%>/keyWord.do?action=delete" ,
								type:'post', 
								dataType:'action', 
								data: id ,  
								success:update_page
	           					}); 
	          				}
					 }else{
					   alert("请选择某行删除！");
					 }
				}else if (com=='增加'){
					$('#cssrain').trigger("click");
				}else if(com == '修改'){
				
					if( $('.trSelected',grid).length>0){
						  
						  if($('.trSelected',grid).length>0&&$('.trSelected',grid).length>1){
						  	alert("不能选择多行！请选择一行数据进行修改！");
						  }
						  
						  var  id = $('.trSelected',grid).find("td:first").eq(0).text();
							openWinrain("edit",id);
					 }else{
					   alert("请选择某行数据修改！");
					 }
					 
				}else if(com == '复制'){
					if( $('.trSelected',grid).length>0){
						  
						  if($('.trSelected',grid).length>0&&$('.trSelected',grid).length>1){
						  	alert("不能选择多行！请选择一行数据进行复制！");
						  }
						  
						  var  id = $('.trSelected',grid).find("td:first").eq(0).text();
							openWinrain("copy",id);
					 }else{
					   alert("请选择某行数据复制！");
					 }
				}			
			}
			
			function update_page(obj) {
				if(obj=='true'){
		         	window.location.reload();
		         }else{
		         	$('#errorrain').trigger("click");
		         }
	     	} 	
	     	//用于展示N级别数据grid
	     	function gridDblclick(){
	     		window.location.href="<%=request.getContextPath()%>/pages/admin/userinfo.jsp?url=0000000";
	     	}
    		function openWinrain(type,id){ 
     	    	 $('#cssrainupdate').attr('href',"<%=request.getContextPath()%>/keyWord.do?action=initDetail&id="+id+"&type="+type);
     	 	 	$('#cssrainupdate').trigger("click");
	     	}
	</script>
	<div style="display:none;">
		<input type="button" id="editrain" href="<%=request.getContextPath() %>/common/delErro.html?height=200&amp;width=300" title="出错信息！" class="thickbox" value="" />
	</div>	
	</body>
</html>
